import java.io.File;
import java.io.FileFilter;
import java.util.Random;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque;

public class Indexer implements Runnable {
	private final BlockingDeque<File> queue;
	private final BlockingDeque<File>[] queues;
	private final Random rnd;
	private static volatile boolean ready;

	public Indexer(BlockingDeque<File> queue, BlockingDeque<File>[] queues) {
		this.queue = queue;
		this.queues = queues;
		rnd = new Random();
	}

	public void run() {
		while (!Thread.interrupted()) {
			File f = queue.poll();
			if (f == IndexService.POISON_PILL)
				return;
			if (f == null) {
				int n = rnd.nextInt(queues.length);
				f = f == null ? queues[n].pollLast() : f;
				if (f == IndexService.POISON_PILL)
					queues[n].addLast(f);
			}
			if (f != null)
				indexFile(f);
			else
				Thread.yield();
		}
	}

	private void indexFile(File f) {
	}
}